﻿using System;
using Eassets.Layered.Domain.Asset;
using System.Data.SqlClient;
using System.Data;
using System.Collections.ObjectModel;
using Eassets.Layered.Domain;

namespace Eassets.Data.Asset
{
    public class AssetItemDetailsData
    {
        /// <summary>
        /// Add asset item details
        /// </summary>
        /// <param name="assetItemDetails"></param>
        public void AddAssetItemDetails(AssetItemDetails assetItemDetails)
        {
            SqlCommand command = new SqlCommand("SP_AddAssetItemDetails"); // Name of the SP
            CommonData commonData = new CommonData(); 
            commonData.ExecuteNonQuery(ConstructCommand(command, assetItemDetails));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="assetItemDetails"></param>
        /// <param name="organizationLevelListAsset"></param>
        public void SaveTransactions(AssetItemDetails assetItemDetails, OrganizationLevelListAsset organizationLevelListAsset)
        {
            SqlCommand commandItemDetails = new SqlCommand("SP_SaveTransactions"); // Name of the SP
            SqlCommand command = new SqlCommand("SP_AddOrganizationLevelListAsset"); // Name of the SP
            //try
            //{
            //    command.Parameters.AddWithValue("@NoOfAssets", organizationLevelListAsset.NoOfAssets);
            //}
            //catch (Exception)
            //{ }
            CommonData commonDatas = new CommonData();
            commonDatas.ExecuteNonQuery(ConstructCommand(commandItemDetails, assetItemDetails));
            CommonData commonData = new CommonData();
            commonData.ExecuteNonQuery(ConstructCommandorganizationLevelListAsset(command, organizationLevelListAsset));
        }

        /// <summary>
        /// Update asset item details
        /// </summary>
        /// <param name="assetItemDetails"></param>
        public void ModifyAssetItemDetails(AssetItemDetails assetItemDetails)
        {
            SqlCommand command = new SqlCommand("SP_ModifyAssetItemDetails"); // Name of the SP
            command.Parameters.AddWithValue("@ItemDetailsId", assetItemDetails.ItemDetailsId);
            CommonData commonData = new CommonData();
            commonData.ExecuteNonQuery(ConstructCommand(command, assetItemDetails));
        }

        /// <summary>
        /// Updates assetItemDetails with Disposal Status.
        /// </summary>
        /// <param name="assetItemDetails"></param>
        public void UpdateAssetItemDetailsStatus(AssetItemDetails assetItemDetails)
        {
            SqlCommand command = new SqlCommand("SP_UpdateAssetItemDetailsStatus"); // Name of the SP
            command.Parameters.AddWithValue("@AssetId", assetItemDetails.AssetId);
            command.Parameters.AddWithValue("@AssetSerialCode", assetItemDetails.AssetSerialCode);
            command.Parameters.AddWithValue("@AssetStatus", assetItemDetails.AssetStatus);
            command.CommandType = CommandType.StoredProcedure;
            CommonData commonData = new CommonData();
            commonData.ExecuteNonQuery(command);
        }

        /// <summary>
        /// Update AssetItemDetails With CurrentBookValue And RemLifeTime
        /// </summary>
        /// <param name="assetItemDetails"></param>
        public void UpdateAssetItemDetailsWithCurrentBookValueAndRemLifeTime(AssetItemDetails assetItemDetails)
        {
            SqlCommand command = new SqlCommand("SP_UpdateAssetItemDetailsFromRevaluation"); // Name of the SP
            command.Parameters.AddWithValue("@AssetId", assetItemDetails.AssetId);
            command.Parameters.AddWithValue("@AssetSerialCode", assetItemDetails.AssetSerialCode);
            command.Parameters.AddWithValue("@CurrentBookValue", assetItemDetails.CurrentBookValue);
            command.Parameters.AddWithValue("@RemainingLifeTime", assetItemDetails.RemainingLifeTime);
            command.CommandType = CommandType.StoredProcedure;
            CommonData commonData = new CommonData(); commonData.ExecuteNonQuery(command);
        }

        /// <summary>
        /// Update asset custodian
        /// </summary>
        /// <param name="assetItemDetails"></param>
        public void UpdateCustodian(AssetItemDetails assetItemDetails)
        {
            SqlCommand command = new SqlCommand("SP_UpdateCustodian"); // Name of the SP
            command.Parameters.AddWithValue("@AssetId", assetItemDetails.AssetId);
            command.Parameters.AddWithValue("@AssetSerialCode", assetItemDetails.AssetSerialCode);

            command.CommandType = CommandType.StoredProcedure;
            CommonData commonData = new CommonData(); commonData.ExecuteNonQuery(command);
        }

       /// <summary>
        /// Delete assetItemDetails.
       /// </summary>
       /// <param name="assetItemDetailsId"></param>
        public void DeleteAssetItemDetails(long assetItemDetailsId)
        {
            SqlCommand command = new SqlCommand("SP_DeleteAssetItemDetails"); // Name of the SP
            command.Parameters.AddWithValue("@AssetItemDetailsId", assetItemDetailsId);
            command.CommandType = CommandType.StoredProcedure;
            CommonData commonData = new CommonData(); commonData.ExecuteNonQuery(command);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="organizationLevelListId"></param>
        /// <param name="assetId"></param>
        /// <returns></returns>
        public Collection<AssetItemDetails> GetAllAssetItemDetailsByOrganizationLevelListId(long organizationLevelListId, long assetId)
        {

            SqlCommand command = new SqlCommand("SP_GetAllAssetItemDetailsByOrganizationLevelListId");
            Collection<AssetItemDetails> assetItemDetailss = new Collection<AssetItemDetails>();
            //AssetItemDetails assetItemDetail;
            command.Parameters.AddWithValue("@OrganizationLevelListId", organizationLevelListId);
            command.Parameters.AddWithValue("@AssetId", assetId);
            command.CommandType = CommandType.StoredProcedure;
            CommonData commonData = new CommonData(); SqlDataReader dataReader = commonData.ExecuteReader(command);
            AssetItemDetails assetItemDetail;
            while (dataReader.Read())
            {
                assetItemDetail = new AssetItemDetails();
                if (!(String.IsNullOrEmpty(dataReader["AssetId"].ToString())))
                {
                    assetItemDetail.AssetId = Convert.ToInt64(dataReader["AssetId"]);
                }
                Assets asset = new Assets();
                AssetData assetData = new AssetData();
                assetItemDetail.Assets = assetData.GetByIdAsset(assetItemDetail.AssetId);
                if (!(String.IsNullOrEmpty(dataReader["AssetSerialCode"].ToString())))
                {
                    assetItemDetail.AssetSerialCode = Convert.ToString(dataReader["AssetSerialCode"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["AssetStatus"].ToString())))
                {
                    assetItemDetail.AssetStatus = Convert.ToString(dataReader["AssetStatus"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["PurchasedDate"].ToString())))
                {
                    assetItemDetail.PurchasedDate = Convert.ToDateTime(dataReader["PurchasedDate"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["PurchasedValue"].ToString())))
                {
                    assetItemDetail.PurchasedValue = Convert.ToDecimal(dataReader["PurchasedValue"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["DepreciatedValue"].ToString())))
                {
                    assetItemDetail.PurchasedValue = Convert.ToDecimal(dataReader["DepreciatedValue"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["CumulativeDepValue"].ToString())))
                {
                    assetItemDetail.CumulativeDepValue = Convert.ToDecimal(dataReader["CumulativeDepValue"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["CurrentBookValue"].ToString())))
                {
                    assetItemDetail.CurrentBookValue = Convert.ToDecimal(dataReader["CurrentBookValue"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["RemainingLifeTime"].ToString())))
                {
                    assetItemDetail.RemainingLifeTime = Convert.ToInt16(dataReader["RemainingLifeTime"]);
                }
                assetItemDetailss.Add(assetItemDetail);
            }
            dataReader.Close();
            return assetItemDetailss;

        }

        /// <summary>
        /// Get assetItemDetails by asset id 
        /// </summary>
        /// <param name="AssetId"></param>
        /// <returns></returns>
        public Collection<AssetItemDetails> GetAssetItemDetailsByAssetId(long AssetId)
        {
            SqlCommand command = new SqlCommand("SP_GetAssetItemDetailsForGetEmployeeByAssetId");
            command.Parameters.AddWithValue("@AssetId", AssetId);
            command.CommandType = CommandType.StoredProcedure;
            CommonData commonData = new CommonData(); SqlDataReader dataReader = commonData.ExecuteReader(command);
            Collection<AssetItemDetails> assetItemDetails = new Collection<AssetItemDetails>();
            AssetItemDetails assetItemDetail;
            while (dataReader.Read())
            {
                assetItemDetail = new AssetItemDetails();
                if (!(String.IsNullOrEmpty(dataReader["EmployeeID"].ToString())))
                {
                    assetItemDetail.EmployeeID = Convert.ToInt64(dataReader["EmployeeId"]);
                }
                EmployeeData employeeData = new EmployeeData();
                Employee employee = new Employee();

                assetItemDetail.Employee = employeeData.GetByIdEmployee(Convert.ToInt64(assetItemDetail.EmployeeID));

                //if (!(String.IsNullOrEmpty(dataReader["EmployeeName"].ToString())))
                //{
                //   assetItemDetail.Employee.EmployeeName = Convert.ToString(dataReader["EmployeeName"]);
                //}
                assetItemDetails.Add(assetItemDetail);
            }
            dataReader.Close();
            return assetItemDetails;
        }

        /// <summary>
        ///Get assetItemDetails by Id 
        /// </summary>
        /// <param name="assetItemDetailsId"></param>
        /// <returns></returns>
        public AssetItemDetails GetByIdAssetItemDetails(long assetItemDetailsId)
        {
            SqlCommand command = new SqlCommand("SP_GetAssetItemDetailsById");
            command.Parameters.AddWithValue("@ItemDetailsId", assetItemDetailsId);
            command.CommandType = CommandType.StoredProcedure;
            CommonData commonData = new CommonData(); SqlDataReader dataReader = commonData.ExecuteReader(command);
            AssetItemDetails assetItemDetails = new AssetItemDetails();
            while (dataReader.Read())
            {
                if (!(String.IsNullOrEmpty(dataReader["ItemDetailsId"].ToString())))
                {
                    assetItemDetails.ItemDetailsId = Convert.ToInt64(dataReader["ItemDetailsId"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["OrganizationLevelListId"].ToString())))
                {
                    assetItemDetails.OrganizationLevelListId = Convert.ToInt64(dataReader["OrganizationLevelListId"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["AssetId"].ToString())))
                {
                    assetItemDetails.AssetId = Convert.ToInt64(dataReader["AssetId"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["AssetSerialCode"].ToString())))
                {
                    assetItemDetails.AssetSerialCode = Convert.ToString(dataReader["AssetSerialCode"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["AssetStatus"].ToString())))
                {
                    assetItemDetails.AssetStatus = Convert.ToString(dataReader["AssetStatus"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["PurchasedDate"].ToString())))
                {
                    assetItemDetails.PurchasedDate = Convert.ToDateTime(dataReader["PurchasedDate"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["PurchasedValue"].ToString())))
                {
                    assetItemDetails.PurchasedValue = Convert.ToDecimal(dataReader["PurchasedValue"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["DepreciatedValue"].ToString())))
                {
                    assetItemDetails.DepreciatedValue = Convert.ToDecimal(dataReader["DepreciatedValue"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["CumulativeDepValue"].ToString())))
                {
                    assetItemDetails.CumulativeDepValue = Convert.ToDecimal(dataReader["CumulativeDepValue"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["CurrentBookValue"].ToString())))
                {
                    assetItemDetails.CurrentBookValue = Convert.ToDecimal(dataReader["CurrentBookValue"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["RemainingLifeTime"].ToString())))
                {
                    assetItemDetails.RemainingLifeTime = Convert.ToInt16(dataReader["RemainingLifeTime"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["RemainingLifetimeUOM"].ToString())))
                {
                    assetItemDetails.RemainingLifetimeUOM = Convert.ToString(dataReader["RemainingLifetimeUOM"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["EmployeeID"].ToString())))
                {
                    assetItemDetails.EmployeeID = Convert.ToInt64(dataReader["EmployeeID"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["Warranty"].ToString())))
                {
                    assetItemDetails.Warranty = Convert.ToString(dataReader["Warranty"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["Barcode"].ToString())))
                {
                    assetItemDetails.Barcode = Convert.ToString(dataReader["Barcode"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["StatusID"].ToString())))
                {
                    assetItemDetails.StatusID = Convert.ToString(dataReader["StatusID"]);
                }
            }
            dataReader.Close();
            return assetItemDetails;
        }

        /// <summary>
        /// GetAll assetItemDetails.
        /// </summary>
        /// <returns></returns>
        public Collection<AssetItemDetails> GetAllAssetItemDetails()
        {
            Collection<AssetItemDetails> assetItemDetailss = new Collection<AssetItemDetails>();
            SqlCommand command = new SqlCommand("SP_GetAllAssetItemDetails");

            command.CommandType = CommandType.StoredProcedure;
            command.CommandTimeout = 600;
            CommonData commonData = new CommonData(); SqlDataReader dataReader = commonData.ExecuteReader(command);
            AssetItemDetails assetItemDetails;
            while (dataReader.Read())
            {
                assetItemDetails = new AssetItemDetails();
                if (!(String.IsNullOrEmpty(dataReader["ItemDetailsId"].ToString())))
                {
                    assetItemDetails.ItemDetailsId = Convert.ToInt64(dataReader["ItemDetailsId"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["OrganizationLevelListId"].ToString())))
                {
                    assetItemDetails.OrganizationLevelListId = Convert.ToInt64(dataReader["OrganizationLevelListId"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["AssetId"].ToString())))
                {
                    assetItemDetails.AssetId = Convert.ToInt64(dataReader["AssetId"]);
                }
                AssetData assetData = new AssetData();

                assetItemDetails.Assets = assetData.GetByIdAsset(assetItemDetails.AssetId);

                if (!(String.IsNullOrEmpty(dataReader["AssetSerialCode"].ToString())))
                {
                    assetItemDetails.AssetSerialCode = Convert.ToString(dataReader["AssetSerialCode"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["AssetStatus"].ToString())))
                {
                    assetItemDetails.AssetStatus = Convert.ToString(dataReader["AssetStatus"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["PurchasedDate"].ToString())))
                {
                    assetItemDetails.PurchasedDate = Convert.ToDateTime(dataReader["PurchasedDate"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["PurchasedValue"].ToString())))
                {
                    assetItemDetails.PurchasedValue = Convert.ToDecimal(dataReader["PurchasedValue"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["DepreciatedValue"].ToString())))
                {
                    assetItemDetails.DepreciatedValue = Convert.ToDecimal(dataReader["DepreciatedValue"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["CumulativeDepValue"].ToString())))
                {
                    assetItemDetails.CumulativeDepValue = Convert.ToDecimal(dataReader["CumulativeDepValue"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["CurrentBookValue"].ToString())))
                {
                    assetItemDetails.CurrentBookValue = Convert.ToDecimal(dataReader["CurrentBookValue"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["RemainingLifeTime"].ToString())))
                {
                    assetItemDetails.RemainingLifeTime = Convert.ToInt16(dataReader["RemainingLifeTime"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["RemainingLifetimeUOM"].ToString())))
                {
                    assetItemDetails.RemainingLifetimeUOM = Convert.ToString(dataReader["RemainingLifetimeUOM"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["EmployeeID"].ToString())))
                {
                    assetItemDetails.EmployeeID = Convert.ToInt64(dataReader["EmployeeID"]);
                }
                EmployeeData employeeData = new EmployeeData();
                assetItemDetails.Employee = employeeData.GetByIdEmployee(Convert.ToInt64(assetItemDetails.EmployeeID));

                if (!(String.IsNullOrEmpty(dataReader["Warranty"].ToString())))
                {
                    assetItemDetails.Warranty = Convert.ToString(dataReader["Warranty"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["Barcode"].ToString())))
                {
                    assetItemDetails.Barcode = Convert.ToString(dataReader["Barcode"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["StatusID"].ToString())))
                {
                    assetItemDetails.StatusID = Convert.ToString(dataReader["StatusID"]);
                }

                assetItemDetailss.Add(assetItemDetails);
            }
            dataReader.Close();
            return assetItemDetailss;
        }

        /// <summary>
        /// GetAll GetAssetRegistryDetails.
        /// </summary>
        /// <returns></returns>
        public Collection<AssetItemDetails> GetAssetRegistryDetails()
        {
            Collection<AssetItemDetails> assetItemDetailss = new Collection<AssetItemDetails>();
            SqlCommand command = new SqlCommand("SP_GetAssetRegistryDetails");

            command.CommandType = CommandType.StoredProcedure;
            CommonData commonData = new CommonData(); SqlDataReader dataReader = commonData.ExecuteReader(command);
            AssetItemDetails assetItemDetails;
            while (dataReader.Read())
            {
                assetItemDetails = new AssetItemDetails();
                if (!(String.IsNullOrEmpty(dataReader["ItemDetailsId"].ToString())))
                {
                    assetItemDetails.ItemDetailsId = Convert.ToInt64(dataReader["ItemDetailsId"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["C.Code"].ToString())))
                {
                    assetItemDetails.Category.Code = Convert.ToString(dataReader["C.Code"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["O.AssetId"].ToString())))
                {
                    assetItemDetails.AssetId = Convert.ToInt64(dataReader["O.AssetId"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["A.Code"].ToString())))
                {
                    assetItemDetails.Assets.Code = Convert.ToString(dataReader["A.Code"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["A.Description"].ToString())))
                {
                    assetItemDetails.AssetStatus = Convert.ToString(dataReader["A.Description"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["ItemSerial"].ToString())))
                {
                    assetItemDetails.ItemSerial = Convert.ToString(dataReader["ItemSerial"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["PurchasedValue"].ToString())))
                {
                    assetItemDetails.PurchasedValue = Convert.ToDecimal(dataReader["PurchasedValue"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["PurchasedDate"].ToString())))
                {
                    assetItemDetails.PurchasedDate = Convert.ToDateTime(dataReader["PurchasedDate"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["AssetStatus"].ToString())))
                {
                    assetItemDetails.ItemSerial = Convert.ToString(dataReader["AssetStatus"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["CurrentBookValue"].ToString())))
                {
                    assetItemDetails.CurrentBookValue = Convert.ToDecimal(dataReader["CurrentBookValue"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["DepreciatedValue"].ToString())))
                {
                    assetItemDetails.DepreciatedValue = Convert.ToDecimal(dataReader["DepreciatedValue"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["CumulativeDepValue"].ToString())))
                {
                    assetItemDetails.CumulativeDepValue = Convert.ToDecimal(dataReader["CumulativeDepValue"]);
                }
                if (!(String.IsNullOrEmpty(dataReader["RemainingLifeTime"].ToString())))
                {
                    assetItemDetails.RemainingLifeTime = Convert.ToInt16(dataReader["RemainingLifeTime"]);
                }
                //if (!(String.IsNullOrEmpty(dataReader["RemainingLifetimeUOM"].ToString())))
                //{
                //    assetItemDetails.RemainingLifetimeUOM = Convert.ToString(dataReader["RemainingLifetimeUOM"]);
                //}
                if (!(String.IsNullOrEmpty(dataReader["EmployeeID"].ToString())))
                {
                    assetItemDetails.EmployeeID = Convert.ToInt64(dataReader["EmployeeID"]);
                }
                //if (!(String.IsNullOrEmpty(dataReader["Warranty"].ToString())))
                //{
                //    assetItemDetails.Warranty = Convert.ToString(dataReader["Warranty"]);
                //}
                //if (!(String.IsNullOrEmpty(dataReader["Barcode"].ToString())))
                //{
                //    assetItemDetails.Barcode = Convert.ToString(dataReader["Barcode"]);
                //}
                //if (!(String.IsNullOrEmpty(dataReader["StatusID"].ToString())))
                //{
                //    assetItemDetails.StatusID = Convert.ToString(dataReader["StatusID"]);
                //}

                assetItemDetailss.Add(assetItemDetails);
            }
            dataReader.Close();
            return assetItemDetailss;
        }

        public SqlCommand ConstructCommandorganizationLevelListAsset(SqlCommand command, OrganizationLevelListAsset organizationLevelListAsset)
        {
            command.CommandType = CommandType.StoredProcedure;
            try
            {
                command.Parameters.AddWithValue("@OrganizationLevelListId", organizationLevelListAsset.OrganizationLevelListId);
            }
            catch (Exception)
            { }
            try
            {
                command.Parameters.AddWithValue("@AssetId", organizationLevelListAsset.AssetId);
            }
            catch (Exception)
            { }
            try
            {
                command.Parameters.AddWithValue("@NoOfAssets", organizationLevelListAsset.NoOfAssets);
            }
            catch (Exception)
            { }
            return command;
        }




        public SqlCommand ConstructCommand(SqlCommand command, AssetItemDetails assetItemDetails)
        {
            command.CommandType = CommandType.StoredProcedure;
         
            try
            {
                command.Parameters.AddWithValue("@OrganizationLevelListId", assetItemDetails.OrganizationLevelListId);
            }
            catch (Exception)
            { }
            try
            {
                command.Parameters.AddWithValue("@AssetId", assetItemDetails.AssetId);
            }
            catch (Exception)
            { }
            try
            {
                command.Parameters.AddWithValue("@AssetSerialCode", assetItemDetails.AssetSerialCode);
            }
            catch (Exception)
            { }
            try
            {
                command.Parameters.AddWithValue("@AssetStatus", assetItemDetails.AssetStatus);
            }
            catch (Exception)
            { }
            try
            {
                command.Parameters.AddWithValue("@PurchasedDate", assetItemDetails.PurchasedDate);
            }
            catch (Exception)
            { }
            try
            {
                command.Parameters.AddWithValue("@PurchasedValue", assetItemDetails.PurchasedValue);
            }
            catch (Exception)
            { }
            try
            {
                command.Parameters.AddWithValue("@DepreciatedValue", assetItemDetails.DepreciatedValue);
            }
            catch (Exception)
            { }
            try
            {
                command.Parameters.AddWithValue("@CumulativeDepValue", assetItemDetails.CumulativeDepValue);
            }
            catch (Exception)
            { }
            try
            {
                command.Parameters.AddWithValue("@CurrentBookValue", assetItemDetails.CurrentBookValue);
            }
            catch (Exception)
            { }
            try
            {
                command.Parameters.AddWithValue("@RemainingLifeTime", assetItemDetails.RemainingLifeTime);
            }
            catch (Exception)
            { }
            try
            {
                command.Parameters.AddWithValue("@RemainingLifetimeUOM", assetItemDetails.RemainingLifetimeUOM);
            }
            catch (Exception)
            { }
            try
            {
                command.Parameters.AddWithValue("@EmployeeID", assetItemDetails.EmployeeID);
            }
            catch (Exception)
            { }
            try
            {
                command.Parameters.AddWithValue("@Warranty", assetItemDetails.Warranty);
            }
            catch (Exception)
            { }
            try
            {
                command.Parameters.AddWithValue("@Barcode", assetItemDetails.Barcode);
            }
            catch (Exception)
            { }
            try
            {
                command.Parameters.AddWithValue("@StatusID", assetItemDetails.StatusID);
            }
            catch (Exception)
            { }

            return command;
        }

        public String GetLastItemSerial(long assetId)
        {
            String lastSerial = "";
            SqlCommand command = new SqlCommand("SP_GetLastSerial");
            command.Parameters.AddWithValue("@AssetId", assetId);
            command.CommandType = CommandType.StoredProcedure;
            AssetItemDetails assetItemDetails = new AssetItemDetails();
            CommonData commonData = new CommonData(); SqlDataReader dataReader = commonData.ExecuteReader(command);
            while (dataReader.Read())
            {
                lastSerial = Convert.ToString(dataReader["Serial"]).ToString();

            }
            return lastSerial;
        }
    }

}
